local product_id = KEYS[1]

local prefixTask = ARGV[1] or 'unknown'
local prefixProduct = ARGV[2] or 'unknown'


local queue_size = tonumber(redis.call('hget', prefixProduct .. 'queue_size', product_id) or 1)
local concurrencies = tonumber(redis.call('hget', prefixProduct .. 'concurrencies', product_id) or 1)
local priority = tonumber(redis.call('hget', prefixProduct .. 'priority', product_id) or 0)

local tasks = redis.call('hgetall', prefixTask .. KEYS[1])

local wip = 0
local inprogress = 0
local total = 0

for i=2, #tasks, 2 do
    local task = cjson.decode(tasks[i])
    local progress = task['progress']

    if progress < 100 then
        wip = wip + 1

        if progress > 0 then
            inprogress = inprogress + 1
        end
    end

    total = total + 1
end

return { concurrencies, queue_size, priority, total, wip, inprogress }